$(function () {
    //录入
    //全部金额
    $("#wt-body select[name=tuitionNumber]").click(function () {
        $("#wt-body input[name=tuitionAmount]").val($("#wt-body select[name=tuitionNumber] option:selected").data("name"))
        console.log($("#wt-body select[name=tuitionAmount] option:selected").data("name"))
    });
    // 优惠金额
    $("#wt-body select[name=discountInfNumber]").click(function () {
        $("#wt-body input[name=discountAmount]").val($("#wt-body select[name=discountInfNumber] option:selected").data("name"))
        console.log($("#wt-body select[name=discountInfNumber] option:selected").data("name"))
    });
    //剩余床位
    $("#wt-body select[name=dormitoryNumber]").click(function () {
        $("#wt-body input[name=remainingBed]").val($("#wt-body select[name=dormitoryNumber] option:selected").data("name"))
        console.log($("#wt-body select[name=dormitoryNumber] option:selected").data("name"))
    });
    //修改
    // 全部金额
    $("#stu-Info-modify select[name=tuitionNumber]").click(function () {
        $("#stu-Info-modify input[name=tuitionAmount]").val($("#stu-Info-modify select[name=tuitionNumber] option:selected").data("name"))
        console.log($("#stu-Info-modify select[name=tuitionAmount] option:selected").data("name"))
    });
    // 优惠金额
    $("#stu-Info-modify select[name=discountInfNumber]").click(function () {
        $("#stu-Info-modify input[name=discountAmount]").val($("#stu-Info-modify select[name=discountInfNumber] option:selected").data("name"))
        console.log($("#stu-Info-modify select[name=discountInfNumber] option:selected").data("name"))
    });
    //剩余床位
    $("#stu-Info-modify select[name=dormitoryNumber]").click(function () {
        $("#stu-Info-modify input[name=remainingBed]").val($("#stu-Info-modify select[name=dormitoryNumber] option:selected").data("name"))
        console.log($("#stu-Info-modify select[name=dormitoryNumber] option:selected").data("name"))
    });
})
// 录入费用计算
$(function () {
    //费用计算
    $("#wt-body input[name=tuitionPaid]").blur(function() {
        // 全部费用
        var tuitionAmount = Number($("#wt-body input[name=tuitionAmount]").val())
        console.log(tuitionAmount)
        // 优惠费用
        var discountAmount = Number($("#wt-body input[name=discountAmount]").val())
        console.log(discountAmount)
        // 报名费
        var registeryFee = Number($("#wt-body input[name=registeryFee]").val())
        console.log(registeryFee)
        // 已交费用
        var tuitionPaid = Number($("#wt-body input[name=tuitionPaid]").val())
        console.log(tuitionPaid)
        // 剩余费用
        var surplusTuition = tuitionAmount - discountAmount - registeryFee - tuitionPaid
        console.log(surplusTuition)
        // 剩余费用填写
        $("#wt-body input[name=surplusTuition]").val(surplusTuition)

        // return surplusTuition
    })

})
//修改费用计算
$(function () {

    //费用计算
    $("#stu-Info-modify input[name=tuitionPaid]").blur(function() {
        // 全部费用
        var tuitionAmount = Number($("#stu-Info-modify input[name=tuitionAmount]").val())
        console.log(tuitionAmount)
        // 优惠费用
        var discountAmount = Number($("#stu-Info-modify input[name=discountAmount]").val())
        console.log(discountAmount)
        // 报名费
        var registeryFee = Number($("#stu-Info-modify input[name=registeryFee]").val())
        console.log(registeryFee)
        // 已交费用
        var tuitionPaid = Number($("#stu-Info-modify input[name=tuitionPaid]").val())
        console.log(tuitionPaid)
        // 剩余费用
        var surplusTuition = tuitionAmount - discountAmount - registeryFee - tuitionPaid
        console.log(surplusTuition)
        // 剩余费用填写
        $("#stu-Info-modify input[name=surplusTuition]").val(surplusTuition)

        // return surplusTuition
    })

})
//学生信息录入
$(function(){
    $("#all-info-brt").click(function(){
        if(!studentInfoEntry()){
            return
        }
        Confirm("是否提交？",function () {
            var userName = $.cookie("username");
            var token = $.cookie("token");
            //学期
            var semesterNumber=$("select[name=semesterName] option:selected").val();//取下拉菜单选中项的文本
            //姓名
            var studentName=$("input[name=studentName]").val();
            //年龄
            var age=$("input[name=age]").val();
            //性别
            var genderNumber=$("input[type=radio][name=genderNumber]:checked").val();//取判断过后的布尔值
            //电话
            var phone=$("input[name=phone]").val();
            // 学历
            var educationNumber=$("select[name=educationNumber] option:selected").val();//取下拉菜单选中项的文本
            //身份证号
            var identityNumber=$("input[name=identityNumber]").val();
            // 家庭住址
            var homeAddress=$("input[name=homeAddress]").val();
            // 紧急联系人姓名
            var emergencyContactName=$("input[name=emergencyContactName]").val();
            // 与紧急联系人关系
            var emergencyContactRelationshipNumber=$("select[name=emergencyContactRelationshipNumber] option:selected").val();//取下拉菜单选中项的文本
            // 紧急联系人电话
            var emergencyContactPhone=$("input[name=emergencyContactPhone]").val();
            //前职业
            var preVocational=$("input[name=preVocational]").val();
            //总费用
            var tuitionNumber=$("select[name=tuitionNumber] option:selected").val();
            //费用金额
            //var tuitionAmount=$("input[name=tuitionAmount]").val();
            //优惠信息
            var discountInfNumber=$("select[name=discountInfNumber] option:selected").val();
            //优惠金额

            //var discountAmount=$("input[name=discountAmount]").val();
            // 报名费
            var registeryFee=$("input[name=registeryFee]").val();
            // 已缴费用
            var tuitionPaid=$("input[name=tuitionPaid]").val();

            // 剩余费用
            var surplusTuition=$("input[name=surplusTuition]").val();
            //报名日期
            var registrationDate=time($("input[name=registrationDate]").val());//转时间戳
            // 入学类型
            var admissionNumber=$("select[name=admissionNumber] option:selected").val();
            // 介绍人
            var introducer=$("input[name=introducer]").val();
            // 宿舍编号
            var dormitoryNumber=$("select[name=dormitoryNumber] option:selected").val();
            // 剩余床位
            //var remainingBed=$("input[name=remainingBed]").val();
            //备注信息
            var remarks=$("input[name=remarks]").val();
///////////////////////////////////////
            var option={
                "userName":userName,
                "token":token,
                "semesterNumber":semesterNumber,
                "studentName":studentName,
                "age":age,
                "genderNumber":genderNumber,
                "phone":phone,
                "educationNumber":educationNumber,
                "identityNumber":identityNumber,
                "homeAddress":homeAddress,
                "emergencyContactName":emergencyContactName,
                "emergencyContactRelationshipNumber":emergencyContactRelationshipNumber,
                "emergencyContactPhone":emergencyContactPhone,
                "preVocational":preVocational,
                "tuitionNumber":tuitionNumber,
                "discountInfNumber":discountInfNumber,
                "registeryFee":registeryFee,
                "tuitionPaid":tuitionPaid,
                "surplusTuition":surplusTuition,
                "registrationDate":registrationDate,
                "admissionNumber":admissionNumber,
                "introducer":introducer,
                "dormitoryNumber":dormitoryNumber,
                "remarks":remarks
            };
            var data=JSON.stringify(option)
            var url="/entry";
            ajax(url,data);
            cookieNull(value.statusCode)
            if(value.statusCode!="2000"){
                Confirm(value.message)
            }else{
                Confirm(value.message)
                $("input[ type='text']").val("")
            }

        })

    })
});

//联系人新增
$(function(){
    $("#contact-info-brt").click(function(){
        if(!relationshipInfoAdd()){
            return;
        }
        Confirm("是否提交？",function (){
            var userName = $.cookie("username");
            var token = $.cookie("token");
            //联系人新增
            var emergencyContactRelationship=$("input[name=emergencyContactRelationship]").val()
            var option={
                "userName":userName,
                "token":token,
                "emergencyContactRelationship":emergencyContactRelationship
            };
            var url="/addEgcrs";
            var data=JSON.stringify(option)
            ajax(url,data);
            console.log(data)
            cookieNull(value.statusCode)
            if(value.statusCode!="2000"){
                Confirm(value.message)
            }else{
                Confirm(value.message)
                $("input[ type='text']").val("")
            }
        })

    })
})

//入学信息类型新增
$(function(){
    $("#admission-info-brt").click(function(){
        if(!entryTypeAdd()){
            return;
        }
        Confirm("是否提交？",function (){
            var userName = $.cookie("username");
            var token = $.cookie("token");
            //入学类型
            var studentAdmissionType=$("input[name=studentAdmissionType]").val();
            ////////////////////
            var option={
                "userName":userName,
                "token":token,
                "studentAdmissionType":studentAdmissionType
            };
            var data = JSON.stringify(option);
            var url="/addAdmType";
            ajax(url,data);
            cookieNull(value.statusCode)
            if(value.statusCode!="2000"){
                Confirm(value.message)
            }else{
                Confirm(value.message)
                $("input[ type='text']").val("")
            }
        })

    })
});

//学历信息新增
$(function(){
    $("#academic-info-brt").click(function(){
        if(!educationInfoAdd()){
            return;
        }
        Confirm("是否提交？",function (){
            var userName = $.cookie("username");
            var token = $.cookie("token");
            //中文学历
            var academicName=$("input[name=academicName]").val();
            var option={
                "userName":userName,
                "token":token,
                "academicName":academicName
            };
            var data= JSON.stringify(option);
            var url= "/addEducation";
            ajax(url,data);
            cookieNull(value.statusCode)
            if(value.statusCode!="2000"){
                Confirm(value.message)
            }else{
                Confirm(value.message)
                $("input[ type='text']").val("")
            }
        })

    })
});

//学期信息新增
$(function(){
    $("#semester-info-brt").click(function(){
        if(!termInfoAdd()){
            return;
        }
        Confirm("是否提交？",function (){
            var userName = $.cookie("username");
            var token = $.cookie("token");
            //中文学期
            var semesterName =$("input[name=semesterName]").val();
            //开学时间--时间戳
            var startDate=time($("input[name=startDate]").val());//转时间戳
            ///////////////
            var option={
                "userName":userName,
                "token":token,
                "semesterName": semesterName,
                "startDate":startDate
            };
            var data=JSON.stringify(option);
            var url="/addSem";
            ajax(url,data);
            cookieNull(value.statusCode)
            if(value.statusCode!="2000"){
                Confirm(value.message)
            }else{
                Confirm(value.message)
                $("input[ type='text']").val("")
            }
        })

    })
});

//新增宿舍信息
$(function(){
    $("#dormitory-info-brt").click(function(){
        if(!dormitoryInfoAdd()){
            return;
        }
        Confirm("是否提交？",function (){
            var userName = $.cookie("username");
            var token = $.cookie("token");
            //宿舍号
            var dormitoryNumber=$("input[name=dormitoryNumber]").val();
            //总共床位数
            var totalBed=$("input[name=totalBed]").val();
            //男OR女
            var dormitoryProperty=$("input[type=radio][name=genderNumber]:checked").val();
            //宿舍密码
            var roomPassword=$("input[name=roomPassword]").val();
            ///////////////////
            var option={
                "userName":userName,
                "token":token,
                "dormitoryNumber":dormitoryNumber,
                "totalBed":totalBed,
                "dormitoryProperty":dormitoryProperty,
                "roomPassword":roomPassword
            };
            var data = JSON.stringify(option);
            var url="/addDorm";
            ajax(url,data);
            cookieNull(value.statusCode)
            if(value.statusCode!="2000"){
                Confirm(value.message)
            }else{
                Confirm(value.message)
                $("input[ type='text']").val("")
            }
        })

    });

});

//删除宿舍
$(function(){
    $("#dormitory-del-brt").click(function(){
        Confirm("是否提交？",function (){
            var userName = $.cookie("username");
            var token = $.cookie("token");
            //删除宿舍
            var dormitoryNumber=$("#dormitoryInfoDel select[name=dormitoryNumber] option:selected").val();
            console.log(dormitoryNumber)
            var option={
                "userName":userName,
                "token":token,
                "dormitoryNumber":dormitoryNumber
            };
            var url="/delDorm";
            var data=JSON.stringify(option)
            ajax(url,data);
            cookieNull(value.statusCode)
            if(value.statusCode!="2000"){
                Confirm(value.message)
            }else{
                Confirm(value.message)
                $("input[ type='text']").val("")

            }
        })
    })
});

//新增费用信息
$(function(){
    $("#stuTuition-info-brt").click(function(){
        if(!costInfoAdd()){
            return
        }
        Confirm("是否提交？",function (){
            var userName = $.cookie("username");
            var token = $.cookie("token");
            //费用名称
            var stuTuitionName=$("input[name=stuTuitionName]").val();
            //费用金额
            var stuTuitionAmount=$("input[name=stuTuitionAmount]").val();
            //描述
            var tuitionDescription=$("input[name=tuitionDescription]").val();
            ////////
            var option={
                "userName":userName,
                "token":token,
                "stuTuitionName": stuTuitionName,
                "stuTuitionAmount":stuTuitionAmount,
                "tuitionDescription":tuitionDescription
            };
            var data=JSON.stringify(option);
            var url="/addTui";
            ajax(url,data);
            cookieNull(value.statusCode)
            if(value.statusCode!="2000"){
                Confirm(value.message)
            }else{
                Confirm(value.message)
                $("input[ type='text']").val("")
            }
        })

    })
});

//新增优惠信息
$(function(){
    $("#discount-info-brt").click(function(){
        if(!discountInfoAdd()){
            return;
        }
        Confirm("是否提交？",function (){
            var userName = $.cookie("username");
            var token = $.cookie("token");
            //优惠信息
            var discountInfName=$("input[name=discountInfName]").val();
            //优惠金额
            var discountAmount=$("input[name=addDiscountAmount]").val();
            //描述
            var discountDescription=$("input[name=discountDescription]").val();
            ////////
            var option={
                "userName":userName,
                "token":token,
                "discountInfName": discountInfName,
                "discountAmount": discountAmount,
                "discountDescription": discountDescription
            };
            var data=JSON.stringify(option);
            var url="/addDisc";
            ajax(url,data);
            cookieNull(value.statusCode)
            if(value.statusCode!="2000"){
                Confirm(value.message)
            }else{
                Confirm(value.message)
                $("input[ type='text']").val("")
            }
        })

    })
});

//学生信息修改
$(function(){
    $("#stu-modify-brt").click(function(){
        if(!studentInfoModify()){
            return;
        }
        Confirm("是否提交？",function (){
            var userName = $.cookie("username");
            var token = $.cookie("token");
            //学期
            var semester=$("#stu-Info-modify select[name=semesterName] option:selected").val();//取下拉菜单选中项的文本
            //学期翻译值
            //var semesterName=$("#stu-Info-modify select[name=semesterName] option:selected").html();
            //学号
            var studentNumber=$("#stu-Info-modify input[name=studentNumber]").val();
            //姓名
            var studentName=$("#stu-Info-modify input[name=studentName]").val();
            //年龄
            var age=$("#stu-Info-modify input[name=age]").val();
            //性别
            var genderNumber=$("#stu-Info-modify input[type=radio][name=genderNumber]:checked").val();//取判断过后的布尔值
            //电话
            var phone=$("#stu-Info-modify input[name=phone]").val();
            // 学历
            var educationNumber=$("#stu-Info-modify select[name=educationNumber] option:selected").val();//取下拉菜单选中项的文本
            // 学历翻译值
            //var academicName=$("#stu-Info-modify select[name=educationNumber] option:selected").html();
            //身份证号
            var identityNumber=$("#stu-Info-modify input[name=identityNumber]").val();
            // 家庭住址
            var homeAddress=$("#stu-Info-modify input[name=homeAddress]").val();

            // 紧急联系人姓名
            var emergencyContactName=$("#stu-Info-modify input[name=emergencyContactName]").val();
            // 与紧急联系人关系
            var emergencyContactRelationshipNumber=$("#stu-Info-modify select[name=emergencyContactRelationshipNumber]").val();
            // 紧急联系人电话
            var emergencyContactPhone=$("#stu-Info-modify input[name=emergencyContactPhone]").val();

            //前职业
            var preVocational=$("#stu-Info-modify input[name=preVocational]").val();


            // 费用金额
            var tuitionAmount=$("#stu-Info-modify input[name=tuitionAmount]").val();
            // 优惠金额
            var discountAmount=$("#stu-Info-modify input[name=discountAmount]").val();
            // 报名费
            var registeryFee=$("#stu-Info-modify input[name=registeryFee]").val();
            // 已缴费用
            var tuitionPaid=$("#stu-Info-modify input[name=tuitionPaid]").val();
            //剩余费用
            var surplusTuition=$("#stu-Info-modify input[name=surplusTuition]").val();

            //报名日期
            var registrationDate=($("#stu-Info-modify input[name=registrationDate]").val());//转时间戳
            // 入学类型
            var admissionNumber=$("#stu-Info-modify select[name=admissionNumber] option:selected").val();
            // 介绍人
            var introducer=$("#stu-Info-modify input[name=introducer]").val();
            // 宿舍编号
            var dormitoryNumber=$("#stu-Info-modify select[name=dormitoryNumber] option:selected").val();
            // 备注信息
            var remarks=$("#stu-Info-modify input[name=remarks]").val()
            ///////////////////////////////////////
            var option={
                "userName":userName,
                "token":token,
                "semester":semester,
                "studentName":studentName,
                "studentNumber":studentNumber,
                "age":age,
                "genderNumber":genderNumber,
                "phone":phone,
                "educationNumber":educationNumber,
                "identityNumber":identityNumber,
                "homeAddress":homeAddress,
                "preVocational":preVocational,
                "registrationDate":registrationDate,
                "admissionNumber":admissionNumber,
                "introducer":introducer,
                "dormitoryNumber":dormitoryNumber,
                "remarks":remarks,
                "emergencyContactName":emergencyContactName,
                "emergencyContactPhone":emergencyContactPhone,
                "emergencyContactRelationshipNumber":emergencyContactRelationshipNumber,
                "tuitionAmount":tuitionAmount,
                "discountAmount":discountAmount,
                "registeryFee":registeryFee,
                "tuitionPaid":tuitionPaid,
                "surplusTuition":surplusTuition,
                "emergencyContactNumber":localStorage.emergencyContactNumber




            };
            var data=JSON.stringify(option)
            var url="/updateStu";
            ajax(url,data);
            cookieNull(value.statusCode)
            if(value.statusCode!="2000"){
                Confirm(value.message)
            }else{
                Confirm(value.message)
                $("input[ type='text']").val("")
            }
        })

    })
});